home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / TUTOROOT.PAK / STEP12.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  128 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1994 by Borland International
  3. //   Tutorial application -- step12.cpp
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/decframe.h>
  8. #include <owl/dialog.h>
  9. #include <owl/controlb.h>
  10. #include <owl/buttonga.h>
  11. #include <owl/statusba.h>
  12. #include <owl/docmanag.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "step12.rc"
  16.  
  17. class TDrawApp : public TApplication {
  18.   public:
  19.     TDrawApp() : TApplication() {}
  20.  
  21.   protected:
  22.     // Override methods of TApplication
  23.     void InitInstance();
  24.     void InitMainWindow();
  25.  
  26.     // Event handlers
  27.     void EvNewView  (TView& view);
  28.     void EvCloseView(TView& view);
  29.     void EvDropFiles(TDropInfo dropInfo);
  30.     void CmAbout();
  31.   DECLARE_RESPONSE_TABLE(TDrawApp);
  32. };
  33.  
  34. DEFINE_RESPONSE_TABLE1(TDrawApp, TApplication)
  35.   EV_OWLVIEW(dnCreate, EvNewView),
  36.   EV_OWLVIEW(dnClose,  EvCloseView),
  37.   EV_WM_DROPFILES,
  38.   EV_COMMAND(CM_ABOUT, CmAbout),
  39. END_RESPONSE_TABLE;
  40.  
  41. void
  42. TDrawApp::InitMainWindow()
  43. {
  44.   // Construct the decorated frame window
  45.   TDecoratedFrame* frame = new TDecoratedFrame(0, "Drawing Pad", 0, true);
  46.  
  47.   // Construct a status bar
  48.   TStatusBar* sb = new TStatusBar(frame, TGadget::Recessed);
  49.  
  50.   // Construct a control bar
  51.   TControlBar* cb = new TControlBar(frame);
  52.   cb->Insert(*new TButtonGadget(CM_FILENEW, CM_FILENEW, TButtonGadget::Command));
  53.   cb->Insert(*new TButtonGadget(CM_FILEOPEN, CM_FILEOPEN, TButtonGadget::Command));
  54.   cb->Insert(*new TButtonGadget(CM_FILESAVE, CM_FILESAVE, TButtonGadget::Command));
  55.   cb->Insert(*new TButtonGadget(CM_FILESAVEAS, CM_FILESAVEAS, TButtonGadget::Command));
  56.   cb->Insert(*new TSeparatorGadget);
  57.   cb->Insert(*new TButtonGadget(CM_PENSIZE, CM_PENSIZE, TButtonGadget::Command));
  58.   cb->Insert(*new TButtonGadget(CM_PENCOLOR, CM_PENCOLOR, TButtonGadget::Command));
  59.   cb->Insert(*new TSeparatorGadget);
  60.   cb->Insert(*new TButtonGadget(CM_ABOUT, CM_ABOUT, TButtonGadget::Command));
  61.  
  62.   // Insert the status bar and control bar into the frame
  63.   frame->Insert(*sb, TDecoratedFrame::Bottom);
  64.   frame->Insert(*cb, TDecoratedFrame::Top);
  65.  
  66.   // Set the main window and its menu
  67.   SetMainWindow(frame);
  68.   GetMainWindow()->SetMenuDescr(TMenuDescr("COMMANDS",1,0,0,0,0,1));
  69.  
  70.   // Install the document manager
  71.   SetDocManager(new TDocManager(dmSDI | dmMenu));
  72. }
  73.  
  74. void
  75. TDrawApp::InitInstance()
  76. {
  77.   TApplication::InitInstance();
  78.   GetMainWindow()->DragAcceptFiles(true);
  79.   GetDocManager()->CmFileNew();
  80. }
  81.  
  82. void
  83. TDrawApp::EvDropFiles(TDropInfo dropInfo)
  84. {
  85.   if (dropInfo.DragQueryFileCount() != 1)
  86.     ::MessageBox(0, "Can only drop 1 file in SDI mode", "Drag/Drop Error", MB_OK);
  87.   else {
  88.     int fileLength = dropInfo.DragQueryFileNameLen(0)+1;
  89.     char* filePath = new char [fileLength];
  90.     dropInfo.DragQueryFile(0, filePath, fileLength);
  91.     TDocTemplate* tpl = GetDocManager()->MatchTemplate(filePath);
  92.     if (tpl)
  93.       tpl->CreateDoc(filePath);
  94.     delete filePath;
  95.   }
  96.   dropInfo.DragFinish();
  97. }
  98.  
  99. void
  100. TDrawApp::EvNewView(TView& view)
  101. {
  102.   GetMainWindow()->SetClientWindow(view.GetWindow());
  103.   if (!view.IsOK())
  104.     GetMainWindow()->SetClientWindow(0);
  105.   else if (view.GetViewMenu())
  106.     GetMainWindow()->MergeMenu(*view.GetViewMenu());
  107. }
  108.  
  109. void
  110. TDrawApp::EvCloseView(TView& /*view*/)
  111. {
  112.   GetMainWindow()->SetClientWindow(0);
  113.   GetMainWindow()->RestoreMenu();
  114.   GetMainWindow()->SetCaption("Drawing Pad");
  115. }
  116.  
  117. void
  118. TDrawApp::CmAbout()
  119. {
  120.   TDialog(GetMainWindow(), IDD_ABOUT).Execute();
  121. }
  122.  
  123. int
  124. OwlMain(int /*argc*/, char* /*argv*/ [])
  125. {
  126.   return TDrawApp().Run();
  127. }
  128.